﻿using Microsoft.EntityFrameworkCore;
using PlatformUW.Entities;
using PlatformUW.EntityFramework.Mappings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlatformUW.EntityFramework
{
    public class PlatformDBContext : DbContext
    {
        public PlatformDBContext(DbContextOptions<PlatformDBContext> options) : base(options)
        {

        }
         
        /// <summary>
        /// 用实体进行配置的方法
        /// </summary>
        /// <param name="modelBuilder"></param>
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //modelBuilder.ApplyConfigurationsFromAssembly(typeof(PlatformDBContext).Assembly);

            modelBuilder.ApplyConfiguration(new PlayerMap());
            modelBuilder.ApplyConfiguration(new CharacterMap());
            modelBuilder.ApplyConfiguration(new SensorMap());

            modelBuilder.Entity<Player>().HasData(DataSeed.Players);
            modelBuilder.Entity<Characters>().HasData(DataSeed.Characters);
            modelBuilder.Entity<SensorTable>().HasData(DataSeed.Sensors);
        }

        // DbSet properties for your entities can be added here
        public DbSet<Player> Players { get; set; }

        public DbSet<Characters> Characters { get; set; }

        public DbSet<SensorTable> Sensors { get; set; }
    }
}
